import { message } from 'antd';
import { getDetailUrl, getPersonChargeDetail } from '@/services/adjusttask';

export default {
  state: {
    data: {
      // 列表数据
      list: [],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 10,
      },
    },
    batchQuery: {
      // 批量上传数据
      sendType: '1',
      isSerSetFlag: '1',
      progressPercent: 0,
    },
    proBaseList: {},
    proFbList: [],
    probId: '',
    empNameList: [], // 单个调整雇员姓名
    adjustInfo: {
      updateBaseInfo: {}, // 基本信息
      updateInsIde: null, // 缴费人员类别
      updateInsAndAccuLocPkgList: null, // 社保组合
      updateInsPdDecWage: null, // 社保申报工资
      isInsIdeFlag: false, // 是否修改缴费人员类别
      insIdeList: [], // 缴费人员类别列表
      isInsDecWageFlag: false, // 是否修改社保申报工资
    }, // 调整信息
    datailInfo: {},
    getPersonDetailData: { updateBaseInfo: {}, updateCostGenter: {}, updatePdAmo: [] },
  },
  effects: {
    // 查看详情
    *fetchDetail(
      {
        payload: { detailUrl, adjId },
      },
      { call, put }
    ) {
      const response = yield call(getDetailUrl, detailUrl, { adjId });
      if (response.success) {
        yield put({
          type: 'getDetail',
          payload: response.data,
        });
      } else {
        message.error(response.message || '查询失败');
        yield put({
          type: 'getDetail',
          payload: {},
        });
      }
    },
    // 人员及收费详情
    *fetchPersonChargeDetail({ payload }, { call, put }) {
      const response = yield call(getPersonChargeDetail, payload);
      if (response.success) {
        yield put({
          type: 'getPersonDetail',
          payload: response.data,
        });
      } else {
        message.warning(response.message || '获取人员信息：服务端错误');
      }
    },
  },

  reducers: {
    // 问题人员详情
    getProDetail(state, { payload }) {
      return {
        ...state,
        proBaseList: payload,
        proFbList: payload.probFdbkList,
        probId: payload.probId,
      };
    },
    // 社保详情
    getDetail(state, { payload }) {
      return {
        ...state,
        datailInfo: payload,
      };
    },
    // 人员
    getPersonDetail(state, { payload }) {
      return {
        ...state,
        getPersonDetailData: payload,
      };
    },
  },
};
